package com.example.exam.controller;

import com.example.exam.pojo.BookTypePage;
import com.example.exam.pojo.Booktype;
import com.example.exam.service.imp.BookTypeService;
import com.example.exam.util.RespBean;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/bookType")
public class BookTypeController {
    @Autowired
    BookTypeService bookTypeService;


    @ApiOperation(value = "添加书本分类", notes = "添加书本分类")
    @PostMapping("/insertBookType")
    public RespBean insertBookType(@RequestBody @Valid Booktype booktype) {
        bookTypeService.insertBookType(booktype);
        return RespBean.ok("图书分类插入成功");
    }

    @ApiOperation(value = "更新书本分类", notes = "更新书本分类")
    @PostMapping("/updateBookType")
    public RespBean updateBookType(@RequestBody @Valid Booktype booktype) {
        bookTypeService.updateBookType(booktype);
        return RespBean.ok("图书分类更新成功");
    }

    @ApiOperation(value = "查看书本分类", notes = "以分页的形式查询书本分类")
    @GetMapping("/selectBookTypeByLimit")
    public RespBean selectBookTypeByLimit(Long row, Long number) {
       BookTypePage bookTypePage= bookTypeService.selectBookTypeByLimit(row,number);

        return RespBean.ok("查询结果",bookTypePage);
    }

    @ApiOperation(value = "删除书本分类", notes = "以编号删除书本分类")
    @GetMapping("/deleteBookType")
    public RespBean deleteBookType(Long id) {
        bookTypeService.deleteBookType(id);
        return RespBean.ok("图书分类删除成功");
    }

}
